/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2019-2022. All rights reserved.
 * Description: 集合通信算子插件头文件
 * Author: lilianlin
 * Create: 2019-11-28
 */

#ifndef HCOM_PLUGIN_H
#define HCOM_PLUGIN_H

#include "hcom_ops_kernel_info_store.h"
#include "hvd_ops_kernel_info_store.h"
#include "hcom_graph_optimizer.h"
#include "hcom_fusion_optimizer.h"
#include "hvd_graph_optimizer.h"
#include "hcom_ops_stores.h"

using HcomOpsKernelInfoStorePtr = std::shared_ptr<hccl::HcomOpsKernelInfoStore>;
using HvdOpsKernelInfoStorePtr = std::shared_ptr<hccl::HvdOpsKernelInfoStore>;
using HcomGraphOptimizerPtr = std::shared_ptr<hccl::HcomGraphOptimizer>;
using HvdGraphOptimizerPtr = std::shared_ptr<hccl::HvdGraphOptimizer>;
using HcomFusionOptimizerPtr = std::shared_ptr<hccl::HcomFusionOptimizer>;

namespace hccl {
class HcomPlugin {
public:
    static HcomPlugin& Instance();
    ge::Status Initialize(const std::map<string, string>& options);
    ge::Status Finalize();
    void GetOpsKernelInfoStores(map<string, OpsKernelInfoStorePtr> &opKernInfos);
    void GetGraphOptimizerObjs(map<string, GraphOptimizerPtr> &graphOptimizers);
private:
    HcomPlugin();
    ~HcomPlugin();
    ge::Status InitializeHcom(const std::map<string, string>& options);
    ge::Status ProfilingModeParser(const std::map<string, string> &options);
    HcclResult ConfigHcclDeterministic(const std::map<string, string> &options);
    HcclResult ConfigHcclAlgo(const std::map<string, string> &options);
    HcclResult ConfigHcclExecTimeOut(const std::map<string, string> &options);
    static HcclResult HcomSetGroupToTopoInfo(const char *group, uint32_t rankSize);
    static void HcomUnsetGroupToTopoInfo(const char *group);
    int initializeCount_;
    HcomOpsKernelInfoStorePtr hcomOpsKernelInfoStoreInfoPtr_;
    HvdOpsKernelInfoStorePtr hvdOpsKernelInfoStoreInfoPtr_;
    HcomGraphOptimizerPtr hcomGraphOptimizerPtr_;
    HvdGraphOptimizerPtr hvdGraphOptimizerPtr_;
    HcomFusionOptimizerPtr hcomFusionOptimizerPtr_;
};
}
#endif